import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';


@Component({
	selector: 'app-profile-editor',
	templateUrl: './profile-editor.html'
})
export class ProfileEditorComponent implements OnInit {

	formSubmit: boolean = false;
	InfoForm:   FormGroup;
	passForm:   FormGroup;

	constructor(private formBuilder: FormBuilder) { }

	ngOnInit() {}


	initInfoForm() {
		const mobile = '';
		const email  = '';

		this.InfoForm = this.formBuilder.group({
			mobile: ['mobile', [Validators.compose([Validators.required])]],
			email:  ['email',  [Validators.compose([Validators.required])]]
		});
	}

	initPassForm() {
		const current       = '';
		const new_pass      = '';
		const ret_type_pass = '';

		this.passForm = this.formBuilder.group({
			current:       ['current',       [Validators.compose([Validators.required])]],
			new_pass:      ['new_pass',      [Validators.compose([Validators.required])]],
			ret_type_pass: ['ret_type_pass', [Validators.compose([Validators.required])]]
		})
	}

	onSubmitProfile() {
		const values    = this.InfoForm.value;
		const keys      = Object.keys(values);
		this.formSubmit = true;

		if (this.InfoForm.valid) {
			console.log('submit modify profile information ...');
		}
	}

	onSubmitModifyPass() {
		const values    = this.passForm.value;
		const keys      = Object.keys(values);
		this.formSubmit = true;

		if (this.passForm.valid) {
			console.log('submit modify password ...');
		}
	}

}